//
// Created by Administrator on 2024/5/20.
//

#ifndef LUAGRAPHICSENGINE_LOG_H
#define LUAGRAPHICSENGINE_LOG_H

#include "spdlog/common.h"
#include "spdlog/async.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"

using namespace spdlog;
using namespace std;

extern void initLog();

void log(source_loc loc, level::level_enum lvl, const memory_buf_t &buffer);

template<typename... Args>
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> fmt, Args &&...args) {
    memory_buf_t buf;
    fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(args...));
    log(loc, lvl, buf);
}

#define __LogCall(level, ...) write(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#define LogT(...) __LogCall(spdlog::level::trace, __VA_ARGS__)
#define LogD(...) __LogCall(spdlog::level::debug, __VA_ARGS__)
#define LogI(...) __LogCall(spdlog::level::info, __VA_ARGS__)
#define LogW(...) __LogCall(spdlog::level::warn, __VA_ARGS__)
#define LogE(...) __LogCall(spdlog::level::err, __VA_ARGS__)


#endif //LUAGRAPHICSENGINE_LOG_H
